<template>
  <div class="contents">
    <PanelTitle title="区域监控" />
    <div class="mt">
      <div class="tabs">
        <div>
          <a-dropdown :trigger="['click']">
            <a @click.prevent v-if="landStore.land"> {{ landStore.land.name }} </a>
            <template #overlay>
              <a-menu>
                <a-menu-item
                  v-for="item in landStore.landList"
                  :key="item.id"
                >
                  <a href="javascript:;" @click="chooseLand(item)">{{
                    item.name
                  }}</a>
                </a-menu-item>
              </a-menu>
            </template>
          </a-dropdown>
        </div>
      </div>
      <div class="infoPanel">
        <div>
          <div class="infoTitle">地块面积</div>
          <div class="infoNumss">
            <span class="infoNum" v-if="landStore.land">{{ landStore.land.acreage ? landStore.land.acreage : 0 }}</span>
            <span class="infoUnit">亩</span>
          </div>
        </div>
        <div>
          <div class="infoTitle">种植规模</div>
          <div class="infoNumss">
            <span class="infoNum" v-if="landStore.land">{{ landStore.land.plantAcreage ? landStore.land.plantAcreage : 0 }}</span>
            <span class="infoUnit">亩</span>
          </div>
        </div>
      </div>
      <div class="tabs">
        <div>视频监控</div>
      </div>
      <div class="video-p">
        <videoPlayer way="1"
        serialNo="FE7210805" style="height: 100%;width: 100%;"></videoPlayer>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import http from "@/api/http";
import { env } from "@/utils/env";
import PanelTitle from "../../component/PanelTitle.vue";
import { useLandStore } from "@/stores/land";
import { useBaseStore } from "@/stores/base";
import videoPlayer from '@/components/videoPlayer.vue'
const landStore = useLandStore()
const baseStore = useBaseStore()


onMounted(async () => {
  let res = await http({
    url: env.VITE_ZHER_DATA_CENTER + "/base/land/list", 
    method: "get",
    params: { 
      baseId: baseStore.base.id,
    },
  });
  
  
  landStore.landList = res.data

  let have = false
  for(let item of res.data){
    if(item.id == landStore.land.id){
      
      have = true
    }
  }
  if(have){
    chooseLand(landStore.land)
  } else {
    chooseLand(landStore.landList[0])
  }

});

const chooseLand = async (item) => {

  landStore.land = item ? item : {}
  emit("select", item);
};

const emit = defineEmits(["select"]);
</script>

<style scoped lang="scss">
.contents {
  background: linear-gradient(
    to bottom,
    rgba(5, 79, 99),
    rgba(5, 79, 99, 0.1),
    rgba(5, 79, 99)
  );
  border-radius: vh(8);
  border: vh(1) solid rgba(6, 112, 180, 1);
  .mt {
    margin-top: vh(-40);
  }
}

.tabs {
  width: vw(66);
  height: vh(20);
  line-height: vh(20);
  padding: 0 2px;
  background: rgba(8, 35, 53, 0.5);
  border-radius: vh(10);
  text-align: center;
  margin: vh(10) vw(10) 0 vw(10);
  > div {
    height: 100%;
    font-family: Source Han Sans CN;
    font-weight: bold;
    font-size: vh(12);

    background: linear-gradient(0deg, #7ae3ff 0%, #ffffff 60%);
    color: transparent;
    -webkit-background-clip: text;
    cursor: pointer;
  }
}

.infoPanel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 0 vw(15) 0;

  > div {
    box-sizing: border-box;
    width: vw(160);
    height: vh(80);
    background: rgba(9, 36, 44, 0.4);
    border: vh(1) solid #43e7ff;
    padding: 0 vw(20) 0px;
    margin: vh(5) 0;
  }
  .infoTitle {
    color: #fff;
    font-size: vh(10);
    line-height: vh(30);
  }
  .infoNums {
    line-height: vh(20);
  }
  .infoNumss {
    line-height: vh(36);
  }
  .infoNum {
    color: #adffd7;
    font-size: vh(26);
    font: SourceHanSansCN-Bold;
  }
  .infoUnit {
    color: #adffd7;
    font-size: vh(16);
    font: SourceHanSansCN-Bold;
    margin-left: vw(4);
  }
  .infoSub {
    font-weight: 400;
    font-size: vh(10);
    color: #adffd7;
    line-height: vh(20);
  }
}
.video-p{
  height: 18vh;
  width: 80%;
  margin: 1vh auto 0 auto;
}
</style>